var t = a(require("@vant/weapp/toast/toast")), e = a(require("@vant/weapp/dialog/dialog"));

function a(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

getApp();

var i = require("../../utils/api"), n = require("../../utils/request"), o = require("../../utils/config"), s = require("../../utils/date");

Page({
    data: {
        themeColor: getApp().globalData.themeColor,
        activeTab: 0,
        pageIndex1: 1,
        pageIndex2: 1,
        pageSize1: 5,
        pageSize2: 5,
        filmPrintData1: [],
        filmPrintData2: [],
        title1: "点击加载更多",
        title2: "点击加载更多",
        showDetailPopup: !1,
        selectedFilmPrintId: "",
        selectedFilmPrint: {},
        selectedFilmPrintDetails: [],
        imageUrl: o.resourceRoot + "yxbg.png",
        showRefundApplyPopup: !1,
        refundApplyId: "",
        refundApplyName: "",
        refundApplyCheckNo: "",
        refundApplyDetailsName: "",
        refundApplyMobile: "",
        refundApplyReason: ""
    },
    onLoad: function(t) {
        "1" == t.active && this.setData({
            activeTab: 1
        }), this.getList(!0);
    },
    onShow: function() {
        this.getList(!0);
    },
    onTabChange: function(t) {
        this.setData({
            activeTab: t.detail.name,
            pageIndex1: 1,
            pageIndex2: 1
        }), this.getList(!0);
    },
    getList: function(e) {
        var a = this;
        wx.showLoading({
            title: "正在加载中...",
            mask: !0
        });
        var o = 0 == this.data.activeTab ? "0,1" : "2", d = 0 == this.data.activeTab ? this.data.pageSize1 : this.data.pageSize2, r = 0 == this.data.activeTab ? this.data.pageIndex1 : this.data.pageIndex2;
        n.request(n.HttpMethod.POST, i.apiRoute.getFilmPrintByPage + "?pageSize=" + d + "&pageIndex=" + r + "&takeFilmPrintTypeStr=" + o, {}).then(function(i) {
            if ("20000" == i.code) {
                var n = e ? [] : a.data.filmPrintData1, o = e ? [] : a.data.filmPrintData2;
                i.data.records.forEach(function(t) {
                    (t.createTimeStr = s.formatDate(new Date(t.createTime), "yyyy-MM-dd HH:mm:ss"), 
                    0 == a.data.activeTab) && (n.map(function(t) {
                        return t.id;
                    }).indexOf(t.id) <= -1 && n.push(t));
                    1 == a.data.activeTab && (o.map(function(t) {
                        return t.id;
                    }).indexOf(t.id) <= -1 && o.push(t));
                }), wx.hideLoading(), (null == i.data.records || i.data.records.length <= 0) && (0 == a.data.activeTab && a.setData({
                    title1: "我是有底线的"
                }), 1 == a.data.activeTab && a.setData({
                    title2: "我是有底线的"
                }), wx.showToast({
                    title: "已无更多数据",
                    duration: 3e3,
                    mask: !1,
                    icon: "none"
                })), 0 == a.data.activeTab && a.setData({
                    filmPrintData1: n
                }), 1 == a.data.activeTab && a.setData({
                    filmPrintData2: o
                });
            } else (0, t.default)({
                message: i.message,
                duration: 5e3
            }), wx.hideLoading();
        });
    },
    addMore: function() {
        if (0 == this.data.activeTab) {
            var t = this.data.pageIndex1 + 1;
            this.setData({
                pageIndex1: t
            });
        } else {
            var e = this.data.pageIndex2 + 1;
            this.setData({
                pageIndex2: e
            });
        }
        this.getList(!1);
    },
    getFilmPrintDetailList: function(e) {
        var a = this;
        n.request(n.HttpMethod.GET, i.apiRoute.getFilmPrintDetailList + e.target.dataset.id, {}).then(function(t) {
            "20000" == t.code && a.setData({
                selectedFilmPrint: e.target.dataset.content,
                selectedFilmPrintDetails: t.data,
                showDetailPopup: !0
            });
        }).catch(function(e) {
            console.log(e), (0, t.default)({
                message: "获取打印胶片明细异常",
                duration: 5e3
            });
        });
    },
    onPopupClose: function() {
        this.setData({
            showDetailPopup: !1
        });
    },
    getFilmPrintInvoice: function(e) {
        n.request(n.HttpMethod.GET, i.apiRoute.getInvoiceUrl + e.target.dataset.content.orderNo, {}).then(function(e) {
            "20000" == e.code ? wx.navigateTo({
                url: "/pages/webview/webview?h5=".concat(encodeURIComponent(e.data)),
                success: function() {}
            }) : (0, t.default)({
                message: e.message,
                duration: 5e3
            });
        }).catch(function(e) {
            console.log(e), (0, t.default)({
                message: "获取开票链接异常",
                duration: 5e3
            });
        });
    },
    cancelWorkOrder: function(a) {
        var o = this;
        e.default.confirm({
            title: "提示",
            message: "您确定取消此次申请吗？"
        }).then(function() {
            n.request(n.HttpMethod.POST, i.apiRoute.cancelWorkOrder, {
                filmPrintId: a.target.dataset.content.id
            }).then(function(t) {
                "20000" == t.code && o.getList(!0);
            }).catch(function(e) {
                console.log(e), (0, t.default)({
                    message: "取消点击胶片申请异常",
                    duration: 5e3
                });
            });
        }).catch(function() {});
    },
    refundApply: function(t) {
        var a = this;
        this.setData({
            refundApplyId: "",
            refundApplyName: "",
            refundApplyCheckNo: "",
            refundApplyMobile: "",
            refundApplyDetailsName: "",
            refundApplyReason: ""
        });
        var i = "";
        0 == t.target.dataset.content.takeFilmType ? i = t.target.dataset.content.sendUserMobile : 1 == t.target.dataset.content.takeFilmType ? i = t.target.dataset.content.pickSelfUserMobile : 2 == t.target.dataset.content.takeFilmType && (i = t.target.dataset.content.electronicUserMobile), 
        this.setData({
            refundApplyId: t.target.dataset.content.id,
            refundApplyName: t.target.dataset.content.checkUserName,
            refundApplyCheckNo: t.target.dataset.content.checkNo,
            refundApplyMobile: i,
            refundApplyDetailsName: t.target.dataset.content.detailsName
        }), e.default.confirm({
            title: "温馨提示",
            message: "您确定取消此次申请并退款吗？"
        }).then(function() {
            a.setData({
                showRefundApplyPopup: !0
            });
        }).catch(function() {});
    },
    refundApplySubmit: function() {
        var a = this, o = this.data.refundApplyReason.replace(" ", "");
        o ? n.request(n.HttpMethod.POST, i.apiRoute.refundApply, {
            id: this.data.refundApplyId,
            refundReason: o
        }).then(function(t) {
            "20000" == t.code && (a.setData({
                showRefundApplyPopup: !1
            }), e.default.alert({
                title: "温馨提示",
                message: "您已提交取消放射影像胶片打印并退款的申请，工作人员将进行审核，如胶片已打印，则无法退款；如退款成功，系统将于7个工作日内将退款原路返还，请您知悉"
            }).then(function() {
                a.getList(!0);
            }));
        }).catch(function(e) {
            console.log(e), (0, t.default)({
                message: "提交退款申请失败",
                duration: 5e3
            });
        }) : (0, t.default)({
            message: "请填写退款原因",
            duration: 5e3
        });
    }
});